
global user "`c(username)'"
global dirdata "C:\Users\\$user\Dropbox\CCT BJP\data"
global dir1 "$dirdata\Final data"
global dir2 "$dirdata\Results\graphs"
global dir3 "$dirdata\Results\"
cd "$dir3"

use "$dir1\pooled_hh.dta", clear
keep if tau>-5  
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1

g Post=tau>=0
egen w_hoursw_head=rowtotal(w_hoursw_p w_hoursw_m)
g work_head=w_hoursw_head>0 
replace work_head=. if work_m==. & work_p==.
replace w_hoursw_m=. if work_m==.
replace w_hoursw_p=. if work_p==.

***** Group of entry:
g G1=(min_schooling<6)
g G2=(min_schooling==6)
g G3=(min_schooling>6 & min_schooling<=8)


local nwork_lab "# of working adults"
local w_hoursw_t_lab "Hours/week"
local work_head_lab "Worked last week"
local w_hoursw_head_lab "Hours/week"
local work_m_lab "Worked last week"
local work_p_lab "Worked last week"
local w_hoursw_m_lab "Hours/week "
local w_hoursw_p_lab "Hours/week "
local parm Post
local parm_p Post_p
local replace replace


global covs "age spanish schooling hhmale  urban np nchild5  age_sac  c.age_sac#i.year c.np#i.year i.departamento#i.year i.year"
global covs2 "age spanish schooling hhmale  urban np nchild5  age_msac  c.age_msac#i.year c.np#i.year i.departamento#i.year i.year"



 
local spec1 Post i.min_schooling $covs  
local spec4 Post_p i.minp_schooling $covs 
local spec3 Post i.min_schooling $covs2  
local spec2 Post i.min_schooling $covs c.year#c.(G1 G2 G3)
local sample2 "(min_schooling>=5 & min_schooling<8)  "
local sample3 "(min_schooling>=1 & min_schooling<9)  "
local sample4 "(minp_schooling>=1 & minp_schooling<9)  "



*** Minimum age instead of average

local replace replace
foreach x in  work_head w_hoursw_head nwork w_hoursw_t work_m w_hoursw_m work_p w_hoursw_p  {
sum `x' [w=factor] if tau==-1 & `sample3' 
local mean_dv=r(mean)
areg `x'  `spec3' if `sample3' [w=factor], a(departamento) cluster(municipio)
outreg2 using "$dir3\PRobustE", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) adds(Clusters, e(N_clust), Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Sample, 1st-8th, Group linear trends, NO, Region X year FE, NO)   
local replace append
}
**** No weights
local replace replace
foreach x in  work_head w_hoursw_head nwork w_hoursw_t work_m w_hoursw_m work_p w_hoursw_p  {
sum `x' if tau==-1 & `sample3' 
local mean_dv=r(mean)
areg `x'  `spec1' if `sample3' , a(departamento) cluster(municipio)
outreg2 using "$dir3\PRobustD", excel `replace' ctitle(``x'_lab') keep(`parm') less(0) nocons  bdec(3) adds(Clusters, e(N_clust), Mean DV, `mean_dv') alpha(0.01, 0.05, 0.1) addtext(Sample, 1st-8th, Group linear trends, NO, Region X year FE, NO)   
local replace append
}


